package disk

import (
	"fmt"
	"github.com/shirou/gopsutil/v3/disk"
	monproto "gollect/proto"
	"time"
)

func Collect(interval time.Duration) *monproto.DiskInfo {
	partitions, err := disk.Partitions(true)
	if err != nil {
		fmt.Printf("Error getting disk partitions: %v\n", err)
		return &monproto.DiskInfo{}
	}
	var pbPartitions []*monproto.DiskPartition
	fmt.Println("\n=== Disk Information ===")
	for _, p := range partitions {
		usage, err := disk.Usage(p.Mountpoint)
		if err == nil {
			fmt.Printf("\nMountpoint: %s\n", p.Mountpoint)
			fmt.Printf("Total: %d bytes\n", usage.Total)
			fmt.Printf("Used: %d bytes\n", usage.Used)
			fmt.Printf("Free: %d bytes\n", usage.Free)
			fmt.Printf("Used Percent: %.2f%%\n", usage.UsedPercent)
			
			pbPartitions = append(pbPartitions, &monproto.DiskPartition{
				Mountpoint:   p.Mountpoint,
				Total:        usage.Total,
				Used:         usage.Used,
				Free:         usage.Free,
				UsedPercent:  float32(usage.UsedPercent / 100.0),
			})
		}
	}
	return &monproto.DiskInfo{
		Partitions: pbPartitions,
	}
} 